//controlls
define(function (require, exports, module) {
    const Vue=require("vue");
    var template=require('text!./index.html');
    const api=require("api");
    const sdk=require("sdk");
    const weui=require('weui');
    module.exports=Vue.extend({
        template:template,
        data:function () {
            return {
                active:'income',
                inComeInfo:[],
                outInfo:[]
            }
        },
        created:function () {

        },
        computed:{
            isBack:function () {
                return this.$store.getters.getIsBack;
            },
            user_info:function () {
                return this.$store.getters.getUserInfo;
            }
        },
        beforeRouteEnter:function (to,from,next) {
            next(function (vm) {
                if(!vm.isBack){
                    vm.getInComeInfo();
                    vm.getOutInfo();
                }
            })
        },
        methods:{
            headerClick:function (text) {
                this.active=text;
            },
            //获取收入信息
            getInComeInfo:function () {
                var v=this;
                var loading = weui.loading('loading……');
                api.chargeInfo("1","100","1","1",v.user_info).then(function (data) {
                    if(data.user_charge_info&&data.user_charge_info.return_code==="SUCCESS"){
                        v.inComeInfo=data.user_charge_info.charge_infos;
                    }else {
                        weui.topTips(data.user_charge_info.return_msg);
                    }
                }).catch(function (e) {
                    weui.topTips("网络异常，请刷新页面再试!");
                }).finally(function () {
                    loading.hide();
                });
            },
            //获取支出信息
            getOutInfo:function () {
                var v=this;
                api.chargeInfo("1","100","1","0",v.user_info).then(function (data) {
                    if(data.user_charge_info&&data.user_charge_info.return_code==="SUCCESS"){
                        v.outInfo=data.user_charge_info.charge_infos;
                    }else {
                        weui.topTips(data.user_charge_info.return_msg);
                    }
                }).catch(function (e) {
                    weui.topTips("网络异常，请刷新页面再试!");
                });
            },
        }
    });
});